import App from './App'

import store from './store'
Vue.prototype.$store = store
// #ifdef H5
import quill from "quill";
window.Quill = quill;
// #endif
// #ifndef VUE3
import Vue from 'vue'
// 引入uview组件库
import uView from 'uview-ui'
Vue.use(uView)
import './uni.promisify.adaptor'

// 导入网络请求的包
import {
  $http
} from '@escook/request-miniprogram'

uni.$http = $http

// 请求的根路径
$http.baseUrl = 'https://haici.snooowball.cn/api/'

setTimeout(function() {
  uni.hideLoading();
  uni.stopPullDownRefresh();
}, 2000);
// 请求拦截器 
$http.beforeRequest = function(options) {
  options.header['token'] = uni.getStorageSync('app_token')
  uni.showLoading({
    title: '加载中...'
  })
}


// 响应拦截器
$http.afterRequest = function(options) {
  if (options.data.code == 201) {
    uni.navigateTo({
      url: '/pages/login/login'
    })
  }
  uni.hideLoading()
}
// 复制
import h5Copy from "./utils/copy.js"
Vue.prototype.copy = function(code) {
  let content = code; // 复制内容，必须字符串，数字需要转换为字符串
  // #ifdef APP-PLUS || MP-WEIXIN
  uni.setClipboardData({
    data: content,
    success: function() {
      uni.showToast({
        title: '复制成功',
        icon: 'none'
      })
    },
  });
  // #endif
  // #ifdef H5
  const result = h5Copy(content)
  if (result === true) {
    uni.showToast({
      title: '复制成功',
      icon: 'none'
    })
  } else {
    uni.showToast({
      title: '复制失败',
      icon: 'none'
    })
  }
  // #endif
};
// 消息提示
import msgUtils from './utils/msgUtils.js'
Vue.prototype.toast = msgUtils

Vue.prototype.go = function(url) {
  uni.navigateTo({
    url: url
  });
}
Vue.prototype.goRedirect = function(url) {
  uni.redirectTo({
    url: url
  });
}
Vue.prototype.switchTab = (url) => {
  uni.switchTab({
    url: url
  })
}

Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif



// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif